import 'package:flutter/material.dart';
import './save/sp_util.dart';
import 'package:get/get.dart';

/// @class : LocaleOptions
/// @date : 2025/01/02
/// @name : shrek
/// @description :主题工具类
class Theme {
  String name = '';
  ThemeIndex mode = ThemeIndex.Syetem;
  Theme(this.name, this.mode);
}

class ThemeOptions {
  ///更新语言
  static updateLocale(BuildContext context, ThemeIndex mode) {
    ThemeMode themeMode;
    // print('themeIndex[mode]');
    // print(themeIndex[mode]);

    switch (themeIndex[mode]) {
      case 0: //跟隨系統
        themeMode = MediaQuery.of(context).platformBrightness == Brightness.dark
            ? ThemeMode.dark
            : ThemeMode.light;
        break;
      case 1: //浅色模式
        themeMode = ThemeMode.light;
        break;
      case 2: //深色模式
        themeMode = ThemeMode.dark;
        break;
      default:
        themeMode = MediaQuery.of(context).platformBrightness == Brightness.dark
            ? ThemeMode.dark
            : ThemeMode.light;
        break;
    }
    //保存到本地
    SpUtil.updateThemeIndex(mode);
    Get.changeThemeMode(themeMode);
  }

  ///获取当前存储的默认语言
  static ThemeMode gethemeDefault(BuildContext context) {
    var index = SpUtil.getThemeIndex();

    ThemeMode themeMode;
    switch (index) {
      case 0: //跟隨系統
        themeMode = MediaQuery.of(context).platformBrightness == Brightness.dark
            ? ThemeMode.dark
            : ThemeMode.light;
        break;
      case 1: //浅色模式
        themeMode = ThemeMode.light;
        break;
      case 2: //深色模式
        themeMode = ThemeMode.dark;
        break;
      default:
        themeMode = MediaQuery.of(context).platformBrightness == Brightness.dark
            ? ThemeMode.dark
            : ThemeMode.light;
        break;
    }

    return themeMode;
  }
}
